package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Address;
import com.ysd.service.impl.AddressServiceImpl;
import com.ysd.util.Result;

@Controller
public class AddressController {
	@Autowired
	AddressServiceImpl addressServiceImpl;
	
	@RequestMapping("getAddress")
	@ResponseBody
	public Object getAddress(int belongToUserId) {
		List<Address> list=addressServiceImpl.findAddresss(belongToUserId);
		return list;
	}
	@RequestMapping("tjAddress")
	@ResponseBody
	public Object tjAddress(Address address) {
		int n=addressServiceImpl.tianJiaAddress(address);
		if (n>0) {//添加成功
			return Result.toClient("0", "添加成功", null, n);
		} else {
			return Result.toClient("1", "添加失败", null, null);
		}
	}
	@RequestMapping("delAdd")
	@ResponseBody
	public Object delAdd(int a_id) {
		int n=addressServiceImpl.deleteAddress(a_id);
		if (n>0) {//删除成功
			return Result.toClient("0", "删除成功", null, n);
		} else {
			return Result.toClient("1", "删除失败", null, null);
		}
	}
	@RequestMapping("selectAdd")
	@ResponseBody
	public Object selectAdd(Address address) {
		Address a=addressServiceImpl.selAddress(address);
		if (a!=null) {
			return Result.toClient("0", "查询成功", null, a);
		} else {
			return Result.toClient("1", "查询失败", null, null);
		}
	}
	@RequestMapping("xgAdd")
	@ResponseBody
	public Object xgAdd(Address address) {
		int n=addressServiceImpl.upAddress(address);
		if (n>0) {//删除成功
			return Result.toClient("0", "修改成功", null, n);
		} else {
			return Result.toClient("1", "修改失败", null, null);
		}
	}
	
}
